package servlet;

import java.io.File;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.hsqldb.Server;

/**
 * @author Paulo Sobreira [sowbreira@gmail.com]
 * @author Rafael Carneiro [rafaelcarneirob@gmail.com]
 */
public class HypersonicServlet extends HttpServlet {

	private Server server = new Server();

	public void init() throws ServletException {

		String dbFile = getServletContext().getRealPath("")
				+ File.pathSeparator + "WEB-INF" + File.pathSeparator
				+ "hipersonic" + File.pathSeparator + "hsqldb";

		server.setDatabaseName(0, "hsqldb");
		server.setDatabasePath(0, "file:" + dbFile);
		server.setLogWriter(new PrintWriter(System.out));
		server.setErrWriter(new PrintWriter(System.out));
		server.setSilent(false);
		server.start();
		System.out.println("Hipersonic Started");
		super.init();
	}

	public void destroy() {
		server.shutdown();
		System.out.println("Hipersonic Stoped");
		super.destroy();
	}

}
